package com.mspbots.web.storage;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

/**
 * com.mspbots.web.core.FileUploadController
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/9/20
 */
@RestController
@RequiredArgsConstructor
public class FileUploadController {

    private final StorageService storageService;

    @PostMapping("/storage/file/{teamsUserId}")
    public Mono handleFileUpload(@PathVariable String teamsUserId,
                                 @RequestPart("file") Mono<FilePart> filePartMono) {
        return this.storageService.store(teamsUserId, filePartMono);
    }

    @ExceptionHandler(StorageFileNotFoundException.class)
    public ResponseEntity<?> handleStorageFileNotFound(StorageFileNotFoundException exc) {
        return ResponseEntity.ok().body(exc);
    }
}
